//
//  ViewController.m
//  TangQiao
//
//  Created by 宜必鑫科技 on 2017/10/11.
//  Copyright © 2017年 宜必鑫科技. All rights reserved.
//
// （导航栏 20 44 + 状态栏）计算高度  64  88  + 52  = 116  140

#import "ViewController.h"
#import "CoreTextController.h"
#import "CoreTextController1.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, assign) float navicationHeight;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIWindow *window;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBar.backgroundColor = [UIColor grayColor];

    //这样视图就不会进行延伸 我们就会把视图控制在导航栏的下面
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.extendedLayoutIncludesOpaqueBars = NO;
    self.modalPresentationCapturesStatusBarAppearance = NO;
    self.title = @"123";
//    self.navigationController.navigationBar.prefersLargeTitles= YES;
    
    CGRect rectOfStatusbar = [[UIApplication sharedApplication] statusBarFrame];
    CGRect rectOfNavigationbar = self.navigationController.navigationBar.frame;
    _navicationHeight = rectOfStatusbar.size.height + rectOfNavigationbar.size.height;
    NSLog(@"navigationbar height: %f", _navicationHeight);   // 高度
    NSLog(@"mainScreen height: %f", HEIGHT);   // 高度
    
    self.view.backgroundColor = [UIColor yellowColor];
    
    
    UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
    but.frame = CGRectMake(0, 0, 100, 50);
    but.backgroundColor = [UIColor whiteColor];
    [but addTarget:self action:@selector(onClickBut) forControlEvents:1<<6];
    [self.view addSubview:but];
    
    UIButton *but1 = [UIButton buttonWithType:UIButtonTypeCustom];
    but1.frame = CGRectMake(120, 0, 100, 50);
    but1.backgroundColor = [UIColor whiteColor];
    [but1 addTarget:self action:@selector(onClickBut1) forControlEvents:1<<6];
    [self.view addSubview:but1];
    
    UIButton *but2 = [UIButton buttonWithType:UIButtonTypeCustom];
    but2.frame = CGRectMake(240, 0, 100, 50);
    but2.backgroundColor = [UIColor whiteColor];
    [but2 addTarget:self action:@selector(onClickBut2) forControlEvents:1<<6];
    [self.view addSubview:but2];
    
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"LDPlayMusicCellId"];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 20;
    self.tableView.frame = CGRectMake(0, 50, WIDTH, HEIGHT - _navicationHeight);
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
}

- (void)onClickBut
{
    _window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    _window.windowLevel = UIWindowLevelNormal;
    _window.backgroundColor = [UIColor redColor];
    _window.userInteractionEnabled = YES;
    _window.hidden = NO;
    
    UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc]init];
    [gest addTarget:self action:@selector(hiddenWindow)];
    [_window addGestureRecognizer:gest];
}
- (void)hiddenWindow
{
    _window.hidden = YES;
    _window = nil;
}

- (void)onClickBut1
{
    CoreTextController *vc = [[CoreTextController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)onClickBut2
{
    CoreTextController1 *vc = [[CoreTextController1 alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 100;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LDPlayMusicCellId"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    int R = (arc4random() % 256) ;
    int G = (arc4random() % 256) ;
    int B = (arc4random() % 256) ;
    cell.backgroundColor = [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ViewController *vc = [[ViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
